package com.zhx.cloud.security;

import com.zhx.cloud.user.entity.User;
import com.zhx.cloud.user.UserDetailSecurity;
import com.zhx.cloud.user.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 *describe: 
 *
 *@author zhanghaixuan
 *@date 2019/02/22
 **/
@Service
public class UserDetialServiceImpl implements UserDetailsService {

	@Autowired
	private UserMapper userMapper;

	@Override
	public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
		User user = new User();
		user.setUsername(s);

		User byUserName = userMapper.findByUserName(s);

		UserDetailSecurity userDetailSecurity  = new UserDetailSecurity();

		userDetailSecurity.setUid(byUserName.getUid());
		userDetailSecurity.setUsername(byUserName.getUsername());
		userDetailSecurity.setPassword(byUserName.getPassword());

		return userDetailSecurity;
	}
}
